#include "StdAfx.h"
#include "Vector3.h"

VAMPIRE_NAMESPACE_BEGIN

Vector3::Vector3( const Real& x, const Real& y, const Real& z )
{
	mData.x = x;
	mData.y = y;
	mData.z = z;
}

Vector3 Vector3::operator+( const Vector3& rhs ) const
{
	return Vector3(mData + rhs.mData);
}

Vector3 Vector3::operator+() const
{
	return *this;
}

Vector3 Vector3::operator-( const Vector3& rhs ) const
{
	return Vector3(mData - rhs.mData);
}

Vector3 Vector3::operator*( const Real& rhs ) const
{
	return Vector3(mData * rhs);
}	

Vector3 Vector3::operator*( const Vector3& rhs ) const
{
	Vector3 result;
	D3DXVec3Cross(&(result.mData), &mData, &(rhs.mData));
	return result;
}

Vector3 Vector3::operator/( const Real& rhs ) const
{
	return Vector3(mData / rhs);
}

Vector3& Vector3::operator+=( const Vector3& rhs )
{
	mData += rhs.mData;
	return *this;
}

Vector3& Vector3::operator-=( const Vector3& rhs )
{
	mData -= rhs.mData;
	return *this;
}

Vector3& Vector3::operator*=( const Real& rhs )
{
	mData *= rhs;
	return *this;
}

Vector3& Vector3::operator*=( const Vector3& rhs )
{
	D3DXVec3Cross(&(mData), &mData, &(rhs.mData));
	return *this;
}

Vector3& Vector3::operator/=( const Real& rhs )
{
	mData /= rhs;
	return *this;
}

void Vector3::operator=( const Vector3& rhs )
{
	mData = rhs.mData;
}

void Vector3::operator=( const D3DXVECTOR3& rhs )
{
	mData = rhs;
}

bool Vector3::operator==( const Vector3& rhs ) const
{
	return mData == rhs.mData ? true : false;
}

bool Vector3::operator!=( const Vector3& rhs ) const
{
	return mData == rhs.mData ? false : true;
}

Vector3 Vector3::operator-() const
{
	return Vector3(-mData);
}

Vector3 Vector3::cross( const Vector3& rhs ) const
{
	Vector3 result;
	D3DXVec3Cross(&(result.mData), &mData, &(rhs.mData));
	return result;
}

Real Vector3::dot( const Vector3& rhs ) const
{
	return D3DXVec3Dot(&mData, &(rhs.mData));
}

void Vector3::normalise()
{
	D3DXVec3Normalize(&mData, &mData);
}

Real Vector3::length() const
{
	return D3DXVec3Length(&mData);
}



Real Vector3::lengthSqrt() const
{
	return D3DXVec3LengthSq(&mData);
}

Vector3 Vector3::add( const Vector3& other ) const
{
	Vector3 sum;
	D3DXVec3Add(&(sum.mData), &mData, &(other.mData));
	return sum;
}

Vector3 Vector3::subtract( const Vector3& other ) const
{
	Vector3 difference;
	D3DXVec3Subtract(&(difference.mData), &mData, &(other.mData));
	return difference;
}

void Vector3::transformCoord( const Matrix44& matrix )
{
	D3DXVec3TransformCoord(&mData, &mData, &(matrix.mData));
}

void Vector3::transformNormal( const Matrix44& matrix )
{
	D3DXVec3TransformNormal(&mData, &mData, &(matrix.mData));
}

void Vector3::scale( const Real& s )
{
	D3DXVec3Scale(&mData, &mData, s);
}

const Vector3 Vector3::UNIT_X(1.0f, 0.0f, 0.0f);
const Vector3 Vector3::UNIT_Y(0.0f, 1.0f, 0.0f);
const Vector3 Vector3::UNIT_Z(0.0f, 0.0f, 1.0f);

const Vector3 Vector3::NEGATIVE_UNIT_X(-1.0f, 0.0f, 0.0f);
const Vector3 Vector3::NEGATIVE_UNIT_Y(0.0f, -1.0f, 0.0f);
const Vector3 Vector3::NEGATIVE_UNIT_Z(0.0f, 0.0f, -1.0f);

const Vector3 Vector3::ZERO(0.0f, 0.0f, 0.0f);

VAMPIRE_NAMESPACE_END

